# -*- coding: utf-8 -*-
#from ragendja.settings_pre import *
from djangoappengine.settings_base import *
import logging
import os
#import cookie_based_session_storage_for_django
from djangoappengine.utils import on_production_server, have_appserver

GOOGLE_FRIEND_CONNECT_SITE_ID = '02335252261937609627'
GOOGLE_FRIEND_CONNECT_CONSUMER_KEY = '*:02335252261937609627'
GOOGLE_FRIEND_CONNECT_CONSUMER_SECRET = 'DIpGrggQaLU='

DEBUG = True

BITLY_USERNAME = 'khaitdoan'
BITLY_API_KEY = 'R_caaa73726ad6c6f4980fb16459c6b471'

if on_production_server:
    ENVIRONMENT = 'production'
    FACEBOOK_API_KEY = 'e7ebd3b01fb4f6a33169a9df3f3a568d'
    FACEBOOK_SECRET_KEY = '4a47a6fd48302b76340cb96c2b0b1eba'
    DEBUG = False
    ADMINS = (('Khai Doan','khaitdoan@gmail.com'))
    ALLOWED_HOSTS = [ '.astoundlearning.com', 'astoundlearning-hrd.appspot.com', 'astoundlearning.appspot.com' ]
else:
    LOGGING = {
        'version': 1,
        'disable_existing_loggers': True,
        'formatters': {
            'verbose': {
                'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
                'datefmt' : "%d/%b/%Y %H:%M:%S"
            },
            'simple': {
                'format': '%(levelname)s %(message)s'
            },
        },
        'handlers': {
            'logfile': {
                'level': 'DEBUG',
                'class': 'logging.FileHandler',
                'filename': 'logfile.txt',
                'mode': 'w',
                'formatter': 'verbose',
            },
        },
        'loggers': {
            '': {
                'handlers': ['logfile'],
                'level': 'DEBUG',
            },
        }
    }
    ENVIRONMENT = 'development'
    FACEBOOK_API_KEY = '39813884f70817c20fc460c058138490'
    FACEBOOK_SECRET_KEY = '1c320e1d69f2e342943c347a20e0c083'
# Increase this when you update your media on the production site, so users
# don't have to refresh their cache. By setting this your MEDIA_URL
# automatically becomes /media/MEDIA_VERSION/
MEDIA_VERSION = 1

# Activate django-dbindexer for the default database
DATABASES['native'] = DATABASES['default']
DATABASES['default'] = {'ENGINE': 'dbindexer', 'TARGET': 'native'}
#AUTOLOAD_SITECONF = 'indexes'

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'astoundmenow'

#ENABLE_PROFILER = True
#ONLY_FORCED_PROFILE = True
#PROFILE_PERCENTAGE = 25
#SORT_PROFILE_RESULTS_BY = 'cumulative' # default is 'time'
#PROFILE_PATTERN = 'ext.db..+\((?:get|get_by_key_name|fetch|count|put)\)'

# Enable I18N and set default language to 'en'
USE_I18N = True
LANGUAGE_CODE = 'en'
EMAIL_HOST = 'localhost'
EMAIL_PORT = 25
EMAIL_SUBJECT_PREFIX = 'AstoundLearning - '

PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
TEMPLATE_DIRS = (
        PROJECT_PATH + '/templates/',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.request',
    'django.core.context_processors.media',
    #
    'django.core.context_processors.media',
    'django.core.context_processors.request',
    'django.core.context_processors.i18n',
    'astoundlearning_app.context_processors.all',

)


MIDDLEWARE_CLASSES = (
    # This loads the index definitions, so it has to come first
    'autoload.middleware.AutoloadMiddleware',

    'django.middleware.common.CommonMiddleware',
    'cookie_based_session_storage_for_django.SessionMiddleware',
    #'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    #
    'django.middleware.locale.LocaleMiddleware',
    #'ragendja.sites.dynamicsite.DynamicSiteIDMiddleware',
    #'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
    #'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
    #'facebook.djangofb.FacebookMiddleware',
)


LOGIN_URL = '/account/login/'
LOGOUT_URL = '/account/logout/'
LOGIN_REDIRECT_URL = '/'

INSTALLED_APPS = (
    #'django.contrib.sessions',
    'django.contrib.admin',
    'django.contrib.contenttypes',
    'django.contrib.auth',
    'django.contrib.sessions',
    'djangotoolbox',
    'autoload',
    'dbindexer',

    # djangoappengine should come last, so it can override a few manage.py commands
    'djangoappengine',
    'astoundlearning_app',
)

# This test runner captures stdout and associates tracebacks with their
# corresponding output. Helps a lot with print-debugging.
TEST_RUNNER = 'djangotoolbox.test.CapturingTestSuiteRunner'

#STATIC_URL = '/static/'
#ROOT_URLCONF = 'urls'
